package com.qf.application.utils.exception;

import com.qf.application.utils.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ControllerExceptionAdvice {


    // 当控制层上抛出了 AppException 就会跳到这里来处理
    @ExceptionHandler(AppException.class)
    @ResponseBody
    public Result appExceptionHandler(AppException appException){
        System.out.println(appException);
        return new Result(appException.getCode(), appException.getMessage(),null);
    }


    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result Exception (Exception e){
        System.out.println("e = " + e);
        return Result.error(500,"系统出现异常，请联系管理员");
    }

}
